On a Fermat principle in general relativity. A Morse Theory for light rays