if both the masked and the reference image have the same pixel extent and size, you can replace the masked values in the band maths with an IF statement as demonstrated here: Replacing NaN with 3x3 average
if both the masked and the reference image have the same pixel extent and size, you can replace the masked values in the band maths with an IF statement as demonstrated here: Replacing NaN with 3x3 average