Commutator Criterion for Constants of Motion