Grading refinements in the contractions of Lie algebras and their invariants