Totally geodesic submanifolds of Riemannian manifolds and curvature-invariant subspaces