Theory and Design of THz Intracavity Gain-Flattened Filters for Monolithically Integrated Mode-Locked Lasers