On geodesics of gradient-index optical metrics and the optical-mechanical analogy