A trend filtering algorithm for wide-field variability surveys