We present a terahertz spatial filter consisting of two back-to-back (B2B) mounted elliptical silicon lenses and an opening aperture defined on a thin gold layer between the lenses. The beam filtering efficiency of the B2B lens system is investigated by simulation and experiment. Using a unidirectional antenna coupled 3rd-order distributed feedback (DFB) quantum cascade laser (QCL) at 3.86 THz as the source, the B2B lens system shows 72% transmissivity experimentally with a fundamental Gaussian mode as the input, in reasonably good agreement with the simulated value of 80%. With a proper aperture size, the B2B lens system is capable of filtering the non-Gaussian beam from the QCL to a nearly fundamental Gaussian beam, where Gaussicity increases from 74% to 99%, and achieves a transmissivity larger than 30%. Thus, this approach is proven to be an effective beam shaping technique for QCLs, making them to be suitable local oscillators in the terahertz range with a Gaussian beam. Besides, the B2B lens system is applicable to a wide frequency range if the wavelength dependent part is properly scaled.