The NuSTAR Serendipitous Survey: The 40-month Catalog and the Properties of the Distant High-energy X-Ray Source Population