Topological invariants for the 4D gapped system are discussed with application to the quantum vacua of relativistic quantum fields. Expression N for the 4D systems with mass gap defined in Volovik (2010)  is considered. It is demonstrated that N remains the topological invariant when the interacting theory in deep ultraviolet is effectively massless. We also consider the 5D systems and demonstrate how 4D invariants emerge as a result of the dimensional reduction. In particular, the new 4D invariant N is suggested. The index theorem is proved that defines the number of massless fermions nF in the intermediate vacuum, which exists at the transition line between the massive vacua with different values of N. Namely, 2nF is equal to the jump ΔN across the transition. The jump ΔN at the transition determines the number of only those massless fermions, which live near the hypersurface ω=0. The considered invariants are calculated for the lattice model with Wilson fermions.