I found the problem. The one not working had the monochrome mask images typed as 'mask', and the working one as 'smask' (according to `pdfimages -list`). I just edited "var mask = xobj.SMask;" to "var mask = xobj.Mask;" and to my astonishment that worked