Please explain to me the ending of Man on a Train (spoilers ahoy!)

I’m not gonna box these spoilers, so here they come:

Elderly teacher goes in for a triple bypass and doesn’t make it: dies on the table, they cover his face and all.

Bank robbery fails – did the teacher tip off the cops? – bank robber is riddled with bullets and dies. (I could see the snipers all over the roof tops as the robbers pulled up, and they could easily have seen them as well is they had looked up.)

But THEN we hear heartbeats and both men come back to life (or at least, open their eyes), and we get that shot of them switching places as the teacher gets on the departing train. Fantasy? Symbolism? Huh? Please to explain, yes?