Microscopy of the beating heart in embryos provides key insights for the study of its development. However, achieving a sufficiently high framerate is difficult with conventional cameras. Here, we present a method to reconstruct an image sequence covering one heartbeat from images acquired over multiple cardiac cycles, with each image triggered at an arbitrary time, by sorting them according to their similarity. We formulate this task as a traveling salesman problem for which efficient solutions are available. We characterized our approach by evaluating its accuracy on synthetically generated data and sub-sampled high-speed movies of the beating heart in zebrafish larvae. We found that reconstructions are reliable when each phase produces a distinct image and when there are no abrupt cardiac motions, which amounts to collecting at least 100 images in a typical microscopy imaging scenario. We finally demonstrate that our method can be applied on data acquired with a fast confocal microscope, increasing its limited frame-rate by a factor 8.