Hi Victor,
When I do hydrogen line observations, I use the frequency switching method to get rid of the SDR artifacts. After taking a hydrogen line spectrum I shift the frequency by about 2 MHz to get a "dark" spectrum. The hydrogen line spectrum is then divided by the frequency switched spectrum. It is not an ideal method, but it works good enough for the hydrogen line because the hydrogen line is a relatively strong signal. There are also other methods of obtaining a dark spectrum, such as covering the antenna with RF absorbing material or pointing the antenna to the ground.
Whatever method you choose, the spectrum will often have a residual slope. You can then fit a line through the parts of the spectrum which do not contain the hydrogen line signal, and divide the.
Using an "empty" part of the sky is indeed not a very good method (at least not for hydrigen line), because the hydrogen line is literally everywhere.
I think the "mask" in the Virgo code is used to define where the standard deviation of the noise in the spectrum (for calculating the signal to noise ratio) is calculated. This has to be done in the parts of the spectrum away from the hydrogen line, so the mask defines which parts of the spectrum should not contain any hydrogen line signal.