Invariants of algebraic groups and retract rationality of classifying spaces