This condition pg_attribute.attnum = ind_atts.attnum is filtering out majority of the bloated indexes.
Ref - JOIN btree_index_atts AS ind_atts ON pg_attribute.attrelid = ind_atts.indexrelid AND pg_attribute.attnum = ind_atts.attnum
This is because attnum of indexes in pg_attribute table will not always match with indkey of index in pg_index table. It will usually match for primary key or initial columns. Thus, pg_attribute.attnum = ind_atts.attnum condition has to be removed.
This condition : pg_stats.attname = pg_catalog.pg_get_indexdef(pg_attribute.attrelid, pg_attribute.attnum, TRUE) while joining with pg_stats will take care of the rest.