If the mass of the particles increases and the Fermi energy stays the same, then the number (density) of the particles must decrease. But the energy levels of the particles depend on their masses as well.
For example, suppose we have a set of $N$ electrons in a cubical box and $N$ protons in another cubical box of the same size. The Fermi energy is defined as the energy of the highest occupied state (more or less.) The most energetic occupied state in each case will have the same values of $\vec{k}$; or to put it another way, the highest occupied wavefunction will be the same in each case. But since the energy of a particle in a box is $k^2 \hbar^2/2 m$, the "most energetic electron" will have a higher energy than the "most energetic proton". Thus, the Fermi energy of the electrons will be higher.
Conversely, if we want to make it so the Fermi energy of the proton gas was the same as the Fermi energy of the electron gas, we would have to add more protons to the box. This would cause the number density of the proton box to go up. When we got to the point where the two Fermi energies were equal to each other, we'd find that there were a lot more protons in the box, and the protons would have a higher number density.
Honestly, it's probably best to think of the Fermi energy as being a function of the density, rather than the other way around.