A generalization of Feynman's variational principle for real path integrals