You can specify the minimum overlap length between a read and a feature (or meta-feature). This can remove too-short reads but will still keep the long reads.
You may use AWK to pre-process the BAM file if you're using Linux or macOS:
$ samtools view -h my_input.bam | awk ' $0~/^@/ {print;next} length($10)>=22 && length($10)<=32 {print} ' > my_output.sam
Then you can count my_output.sam. "length($10)" denotes the length of the read sequence, hence my_output.sam only has the header lines (starting with '@') and reads between 22bp and 32bp long. You can change the conditions applied to "length($10)" to have exact lengths or a range of lengths or their combinations.