first version of mask filter; TODO: automatically estimate threshold