On the existence of solutions to a class of minimum time control problems and applications to Fermat's principle and to the brachystocrone