How to delete connected areas less than a certain threshold

Using setextractionmodetolargestregion() of vtkpolydataconnectivityfilter can get the largest connected area, but other smaller connected areas that you want to keep have also been deleted. I want to reserve connected domains that are greater than a certain threshold, or delete connected domains that are less than a certain threshold. How should I achieve this?