Robust normalizing flows using Bernstein-type polynomials