Semicontinuity of a functional depending on curvature