Varieties of groups and three-manifolds