Implementation of get_next_nearest_checkpoint function.